#include "adminview.h"
#include "ui_adminview.h"

AdminView::AdminView(QWidget *parent,int aid) :
    QMainWindow(parent),
    ui(new Ui::AdminView)
{
    m_aid = aid;
    ui->setupUi(this);
}

AdminView::~AdminView()
{
    delete ui;
}



void AdminView::on_Quit_clicked()
{
    this->~AdminView();
    MainWindow* pmwd = new MainWindow();
    pmwd->show();
}




void AdminView::on_Dialog_listen_clicked()
{
    Service* ps = new Service();
    ps->show();
}


void AdminView::on_servicer_clicked()
{
    Client* pc = new Client(nullptr,m_aid);
    pc->show();
}


void AdminView::on_refresh_clicked()
{
    static QSqlQueryModel *mode1= new QSqlQueryModel(ui->tableView);
    mode1->setQuery("SELECT uid,uaccount,upassword,unickname,utele,upoints,uaddress FROM tb_user ORDER BY upoints DESC" );
    mode1->setHeaderData(0,Qt::Horizontal,tr("uid"));
    mode1->setHeaderData(1,Qt::Horizontal,tr("account"));
    mode1->setHeaderData(2, Qt::Horizontal, tr("password"));
    mode1->setHeaderData(3, Qt::Horizontal, tr("nickname"));
    mode1->setHeaderData(4, Qt::Horizontal, tr("tele"));
    mode1->setHeaderData(5, Qt::Horizontal, tr("points"));
    mode1->setHeaderData(6, Qt::Horizontal, tr("address"));
    ui->tableView->setModel(mode1);

    static QSqlQueryModel *mode2= new QSqlQueryModel(ui->tableView_2);
    mode2->setQuery("SELECT sid,saccount,spassword,sname,sprofit,stele,saddress FROM tb_store ORDER BY sprofit DESC");
    mode2->setHeaderData(0,Qt::Horizontal,tr("sid"));
    mode2->setHeaderData(1,Qt::Horizontal,tr("account"));
    mode2->setHeaderData(2, Qt::Horizontal, tr("password"));
    mode2->setHeaderData(3, Qt::Horizontal, tr("name"));
    mode2->setHeaderData(4, Qt::Horizontal, tr("profits"));
    mode2->setHeaderData(5, Qt::Horizontal, tr("tele"));
    mode2->setHeaderData(6, Qt::Horizontal, tr("address"));
    ui->tableView_2->setModel(mode2);

    static QSqlQueryModel *mode3= new QSqlQueryModel(ui->tableView_3);
    mode3->setQuery("SELECT cid,cname,cnum,cprofit FROM tb_goods_cat ORDER BY cprofit DESC");
    mode3->setHeaderData(0,Qt::Horizontal,tr("cid"));
    mode3->setHeaderData(1, Qt::Horizontal, tr("name"));
    mode3->setHeaderData(2, Qt::Horizontal, tr("num"));
    mode3->setHeaderData(3, Qt::Horizontal, tr("profits"));
    ui->tableView_3->setModel(mode3);
}

